Skip to content

Conversation

suzyahyah
Copy link
Contributor

@suzyahyah suzyahyah commented Oct 10, 2025

This PR handles all the cases of inconsistent datetime related pd.to_numeric handling from Issue 42380 and is compatible with pandas/io/parsers/base_parser.py

  1. pandas/_libs/lib.pyx contains the core/common logic for datetime related pd.to_numeric handling, and is a singular place which handles scalar values, pd.Datetime, pd.TimeStamp and Series(input_value).apply(partial(to_numeric))

    elif convert_datetime and (PyDate_Check(val) or cnp.is_datetime64_object(val)):

  2. pd.Timedelta is returned as the direct value, and pd.Timestamp with Timezones are handled with the default np.datetime64 UTC conversion.

  3. The removal of elif lib.is_np_dtype(values_dtype, "mM"): values = values.view(np.int64) in pandas/core/tools/numeric.py addresses the bug where int value of NaT are returned (Issue 42380).

  4. Introduces convert_datetime flag in maybe_convert_numeric, as this function is used by both pd.to_numeric and the base_parsers, e.g., excel reader. The default behavior for pd.to_numeric on datetimes is to convert to numeric, while the default behavior on base_parsers is to not convert.

convert_datetime: bool = ...,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: pd.to_numeric has an inconsistent behavior for datetime objects

1 participant